<!--
 * @Author: your name
 * @Date: 2022-04-21 10:44:23
 * @LastEditTime: 2022-08-18 15:59:28
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \jk_one-stop_cloud_mobile_v1.0\src\views\apply\recordDetail.vue
-->


<template>
  <div class="recordDetail">
    <Navbar  @eventGetHeight="getHeight" :appTitle="title" />
    <!--头部-->
    <div id="headdd" class="d-head">
      <div class="content">
        <div class="left">
          <div class="title">
            {{$route.query.title}}
          </div>
          <div class="row">{{workOrderInfo.applyNo}}</div>
          <div class="row">{{workOrderInfo.applicantName}},{{workOrderInfo.applyTime}} 发起申请</div>
        </div>
        <!-- <div class="right">
            <img  class="rightImg" v-if="workOrderInfo.flowStatus == 'RUNNING'" src="@/assets/img/shenpizhong.png" alt="">
            <img  class="rightImg" v-if="workOrderInfo.flowStatus == 'AGREE'" src="@/assets/img/yitongguo.png" alt="">
            <img  class="rightImg" v-if="workOrderInfo.flowStatus == 'REFUSE'" src="@/assets/img/yijujue.png" alt="">
            <img  class="rightImg" v-if="workOrderInfo.flowStatus == 'TERMINATED'" src="@/assets/img/yichehui.png" alt="">

        </div> -->
         <div class="right">
          <!--ids="MESS_TASK_REPORT_WORK_APPLY_FOR_PRODUCT" -->
         <imgStatus
          :flowStatus="workOrderInfo.flowStatus"
        ></imgStatus>
        </div>
      </div>
    </div>

    <!-- taps-->
    <!--锚点选项卡-->
    <van-tabs v-model="active" scrollspy sticky :offset-top="runingHeight">
      <!--基本信息 -->
      <van-tab title="基本信息" :style="calssDD">
        <div class="otherTaps">
          <div class="title">
            <span class="icon"></span>
            <span class="content">基本信息</span>
          </div>
          <div class="content" v-if="workOrderInfo.taskDetail">
            <div class="row">
              <span class="r-label">工单编号：</span>
              <span class="r-column">{{workOrderInfo.taskDetail.orderCode}} </span>
            </div>
            <div class="row">
              <span class="r-label">生产物料：</span>
              <span class="r-column">{{ workOrderInfo.taskDetail.goodsCode}} - {{ workOrderInfo.taskDetail.goodsName}}</span>
            </div>
            <div class="row">
              <span class="r-label">工序：</span>
              <span class="r-column">{{ workOrderInfo.taskDetail.processCode}} - {{workOrderInfo.taskDetail.processName}}</span>
            </div>
          </div>
        </div>
      </van-tab>
      <!--操作报工 -->
      <van-tab title="操作报工">
         <div class="otherTaps">
          <div class="title">
            <span class="icon"></span>
            <span class="content">操作报工</span>
          </div>
          <div class="content" v-if="workOrderInfo.taskDetail">
            <div class="row">
              <span class="r-label">批次编号：</span>
              <span class="r-column"><batch-production :code="workOrderInfo.batchCode" :id="workOrderInfo.batchId"></batch-production></span>
            </div>
            <div class="row">
              <span class="r-label">操作人：</span>
              <span class="r-column">{{ workOrderInfo.operatorName}}</span>
            </div>
            <div class="row">
              <span class="r-label">报工总数：</span>
              <span class="r-column">{{numFormat(workOrderInfo.reportWorkNum )}}{{workOrderInfo.taskDetail.processWorkUnitText}}</span>
            </div>
            <div class="row">
              <span class="r-label">合格数：</span>
              <span class="r-column">{{numFormat(workOrderInfo.qualifiedNum)}}{{workOrderInfo.taskDetail.processWorkUnitText}}</span>
            </div>
            <div class="row">
              <span class="r-label">不合格数：</span>
              <span class="r-column">{{numFormat(workOrderInfo.notQualifiedNum )}}{{workOrderInfo.taskDetail.processWorkUnitText}}</span>
            </div>
            <div class="row">
              <span class="r-label">不合格原因：</span>
              <span class="r-column">{{workOrderInfo.notQualifiedReason}}</span>
            </div>
          </div>
        </div>
      </van-tab>
      <!--其它 -->
      <van-tab title="其它">
        <div class="otherTaps">
          <div class="title">
            <span class="icon"></span>
            <span class="content">其它</span>
          </div>
          <div class="content">
            <div class="row">
              <span class="r-label">备注：</span>
              <span class="r-column"
                >{{workOrderInfo.remark || "--"}}</span
              >
            </div>
            <div class="row">
              <span class="r-label">附件：</span>
              <span class="r-column">
                 <span v-if="workOrderInfo.attachment==''">--</span>
                <upload
                  class="fileclass"
                  iconType="fj"
                  @fileChange="fileChange"
                  :fileIds="workOrderInfo.attachment"
                  :showUpload="false"
                ></upload>
              </span>
            </div>
          </div>
        </div>
      </van-tab>
      <!--审批流程 -->
      <van-tab title="审批流程" v-if="workOrderInfo.flowInstId">
        <div class="otherTaps" :style="bottomHeight">
           <div class="title">
            <span class="icon"></span>
            <span class="content">审批流程</span>
          </div>
          <!-- ids="MESS_TASK_REPORT_WORK_APPLY_FOR_PRODUCT"  -->
          <Examine  v-if="workOrderInfo.flowInstId" type="2"
          :id="workOrderInfo.flowInstId" ref="examine" 
          :showTitle="false"/>
              
        </div>
      </van-tab>
    </van-tabs>

    <!--提交按钮 -->
    <div class="search-bottom" v-if="$route.query.applyType == 'waiterDeal' && workOrderInfo.flowStatus == 'RUNNING'">
      <span class="btncancel" @click="cancel">拒绝</span>
      <span class="btnconfirm" @click="confirm">同意</span>
    </div>
  </div>
</template>

<script>
import { recordDetailApi,getFileListByIds} from "@/api/mobile.js";
import { apiBaseUrlDownload, apiBaseUrlUpload } from "@/utils/request";
import Navbar from "@/components/navBar/navBar_right";
import upload from "@/components/upload/upload";
import Examine from "@/components/examine";
import { numFormat } from '@/utils/util'
import { getEnableOne } from "@/api/api";
import imgStatus from "@/components/imgStatus/imgStatus";
import BatchProduction from '@/components/BatchProduction'
export default {
  name: "recordDetail",
  components: { Navbar, upload,Examine,imgStatus, BatchProduction},
  data() {
    return {
      topHeight:"",//导航头的高度
      bodyHeight:"",//获取分辨率 
      runingHeight:"", //锚点选项卡距顶部的高度
      bottomHeight:"padding-bottom:1.5rem",//为了撑开底部 锚点准确
      calssDD: "",//锚点的第一个元素位置
      showFLow:true,
      numFormat,
      parentId:"",
      tableData:[],
      workOrderInfo:{},
      reasonArr: [],//不合格原因
      title: this.$route.meta.title,
      tabList: [
        { name: "发货记录", value: "1" },
        { name: "开票记录", value: "2" },
        { name: "收款记录", value: "2" },
      ],
      active: 0,
      fileIds: "1514159656052879361,1514159725032402946",
    };
  },
   watch: {
    workOrderInfo(newVal) {
      this.$nextTick(() => {
        //  alert("2")
        this.getAfterHeight()
      
      })
    },
  },
  computed: {},
  mounted() {
    
  },
  created() {
    this.parentId = this.$route.query.id
    this.getDetail()
  },
  methods: {
    isShowFLow(){
       getEnableOne({ id: "MESS_TASK_REPORT_WORK_APPLY_FOR_PRODUCT", type: "add" }).then((res) => {
        if (res.result && res.result == "false") {
          this.showFLow = false;
        } else {
          this.showFLow = true;
        }
         this.initHeight(this.topmenuHeiht)
      });   
     },
     getHeight(data){
       this.topHeight=data
       this.getAfterHeight()
     },
     getAfterHeight() {
      this.bodyHeight=document.body.clientHeight;//屏幕高度
      this.runingHeight =this.topHeight+document.getElementById("headdd").offsetHeight-5;
      // this.runingHeight =this.headheight-5;
      this.calssDD = "margin-top:" + (this.runingHeight - this.topHeight) + "px";
      this.isShowFLow();
  
    },
    initHeight(data){
      // alert(data)
      console.log(data,'计算高度')
      this.bodyHeight=document.body.clientHeight;//屏幕高度
       if(this.bodyHeight>=667){
        if(this.showFLow){
           this.bottomHeight="padding-bottom:1.5rem";
        }else{
           this.bottomHeight="padding-bottom:3rem";
          //  alert("ddddddd")

        }
      }
      if(this.bodyHeight>=736){
        if(this.showFLow){
           this.bottomHeight="padding-bottom:2rem";
        }else{
           this.bottomHeight="padding-bottom:3.5rem";

        }
        
      }
      if(this.bodyHeight>=812){
        if(this.showFLow){
           this.bottomHeight="padding-bottom:2.5rem";
        }else{
          this.bottomHeight="padding-bottom:4rem";
        }
         
      }
      if(this.bodyHeight>=844){
        if(this.showFLow){
           this.bottomHeight="padding-bottom:2.8rem";
        }else{
          this.bottomHeight="padding-bottom:5.5rem";
        }
         
      }
      if(this.bodyHeight>=896){
        if(this.showFLow){
           this.bottomHeight="padding-bottom:3rem";
        }else{
           this.bottomHeight="padding-bottom:5.5rem";
        }
      }
     
   
    },
    cancel() {
          // approveType 1:同意 0:拒绝
      this.$router.push({
        path: "/approval",
        query: { approveType: 0, taskId: this.$route.query.taskId},
      });
    },
    confirm() {
        this.$router.push({
        path: "/approval",
        query: { approveType: 1, taskId: this.$route.query.taskId },
      }); 
    },
    fileChange(ids) {
      console.log(ids);
      this.formData.attachment = ids;
    },
    getDetail() {
      recordDetailApi({id:this.parentId}).then((res) => {
        if (res.success) {
          if (res.result) {
            this.workOrderInfo = res.result
            // alert(this.workOrderInfo.flowInstId)
          
            // this.tableData = tableData
          }
        } else {
            this.$toast(res.message);
        }
      })
    },
  },
};
</script>
<style lang="scss" scoped>
.recordDetail {
  height: 100vh;
  overflow-y: scroll;
  background: #ffffff;
  // background: green;
  .d-head {
    position: fixed;
    width: 100%;
    padding: 0.16rem 0.16rem 0.16rem 0.16rem;
    background: #ffffff;
    z-index: 999;
    
    .content {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .left {
        width: 2.8rem;
        // border: 1px solid red;
        .title {
          font-size: 0.16rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #191f25;
          line-height: 0.22rem;

          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          -o-text-overflow: ellipsis;
        }
        .row {
          font-size: 0.14rem;
          font-family: PingFang SC;
          font-weight: 400;
          color: #888888;
          margin-top: 0.16rem;
        }
      }
      .right {
        // border: 1px solid red;
        width: 0.6rem;
        .rightImg {
          display: block;
          width: 0.55rem;
          height: 0.55rem;
          //   margin-left: 0.45rem;
          // border: 1px solid blue;
        }
      }
    }
  }

  .otherTaps {
    background: #ffffff;
    padding: 0.16rem;
    border-top:0.1rem solid rgb(245, 245, 245);
    .title {
      padding-bottom: 0.1rem;
      border-bottom: 1px solid #eeeeee;
      .icon {
        display: inline-block;
        width: 0.03rem;
        height: 0.14rem;
        background: #1890ff;
      }
      .content {
        width: 0.63rem;
        height: 0.16rem;
        font-size: 0.16rem;
        font-family: PingFang SC;
        font-weight: bold;
        color: #191f25;
        line-height: 0.22rem;
        margin-left: 0.1rem;
      }
    }
    .content {
      .row {
        font-size: 0.14rem;
        font-family: PingFang SC;
        font-weight: 400;
        margin-top: 0.16rem;
        display: flex;
        .r-label {
          color: #888888;
          display: block;
          // width: 0.9rem;
          //   border: 1px solid red;
        }
        .r-column {
          display: block;
          color: #191f25;
          width: 2.5rem;
          //   border: 1px solid red;
          //    width: 1rem;
        }
      }
      .fhrow {
        display: flex;
        .fhImg {
          width: 0.55rem;
          height: 0.55rem;
          border-radius: 0.1rem;
        }
        .rt-column {
            width: 2.55rem;
        //   height: 2.55rem;
          margin-left: 0.2rem;
          .rt-title {
            font-size: 0.16rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: #191f25;
            margin-bottom: 0.16rem;
          }
          .rt-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 0.23rem;
            .column {
            //    border: 1px solid red;
               width: 1.5rem;
              .column-t {
                font-size: 0.14rem;
                font-family: PingFang SC;
                font-weight: 400;
                color: #888888;
                display: block;
                width: 100%;
                margin-bottom: 0.03rem;
                
              }
              .column-c {
                font-size: 0.16rem;
                font-family: PingFang SC;
                font-weight: 400;
                color: #191f25;
                display: block;
                width: 100%;
              }
            }
          }
        }
      }
    }
  }
  .search-bottom {
    height: 0.5rem;
    width: 100%;
    background: #ffffff;
    // background: red;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0px;
    padding: 0.11rem;
    .btnconfirm {
      width: 1.72rem;
      height: 0.39rem;
      background: #1890ff;
      border-radius: 0rem;
      text-align: center;
      line-height: 0.39rem;
    }
    .btncancel {
      width: 1.72rem;
      height: 0.39rem;
      background: #f6f6f6;
      border: 0.01px solid rgba(25, 31, 37, 0.12);
      border-radius: 0rem;
      text-align: center;
      line-height: 0.39rem;
    }
  }
}
</style>
<style>
.van-tabs__line {
  background-color: #1890ff;
}
.van-tab--active {
  color: #1890ff;
}
</style>